<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="tag" tagdir="/WEB-INF/tags" %>
<html>
<head>
	<title></title>
	<tag:header/>
</head>
<body id="main_layout">
<div class="winContainer">
	<form id="formMain" action="${pageContext.request.contextPath}/api/${modulePath}/${action}" method="post">
		<%--<form id="formMain" >--%>
		<div class="btnBar">
			<a id="btnSave" href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconcls="icon-save">保存</a>
		</div>
		<div class="headerTable"></div>
	</form>
</div>



</body>
</html>
<script type="text/template" id="headerTmpl">
	<div>
		<div class="col">
			<div class="td">
				<input id="id" type="text" class="widget"/>
			</div>
		</div>
		<!--标题-->
		<div class="col" style="width: 98%;">
			<div class="td">
				<input id="title" data-qfield="title" class="widget"  type="text" style="width: 600px;" />
			</div>
		</div>
		<!--开始时间-->
		<div class="col" style="width: 98%;">
			<div class="td">
				<input id="startTime" data-qfield="startTime" class="easyui-datebox widget" />
			</div>
		</div>
		<!--结束时间-->
		<div class="col" style="width: 98%;">
			<div class="td">
				<input id="endTime" data-qfield="endTime" class="easyui-datebox widget" />
			</div>
		</div>
		<!--调查范围-->
		<p style=" font-weight: bold;  padding: 2px; ">调查范围</p>
		<div>
			<div id="tt" class="easyui-tabs" style="height:340px;">
				<div title="会员" style="padding:5px;">
					<%--<div style="background-color: #e9f1ff;padding: 5px;font-weight: bold;">--%>
					<%--<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconcls="icon-add"--%>
					<%--onclick="addInfo(1)">添加</a>--%>
					<%--<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconcls="icon-delete"--%>
					<%--onclick="cleanInfo(1)">删除</a>--%>
					<%--</div>--%>
					<input id="memberIds" name="memberIds" type="hidden"/>
					<input id="memberPhones" name="memberPhones" type="hidden"/>
					<table class="grid1" id="member_grid" >
						<thead>
						<tr>
							<th>办事处</th>
							<th>会员姓名</th>
							<th>会员电话</th>
							<th>注册渠道</th>
							<th>注册方式</th>
							<th>购买次数</th>
							<th>宝宝数量</th>
							<th>总积分</th>
							<th>已用积分</th>
							<th>未用积分</th>
							<th>推荐人类型</th>
							<th>推荐人姓名</th>
							<th>推荐人电话</th>
							<th>注册时间</th>
						</tr>
						</thead>
						<tbody id="memberItems">
						</tbody>
					</table>
				</div>
				<div title="推荐人" style="padding:5px;">
					<%--<div style="background-color: #e9f1ff;padding: 5px;font-weight: bold;">--%>
					<%--<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconcls="icon-add"--%>
					<%--onclick="addInfo(2)">添加</a>--%>
					<%--<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconcls="icon-delete"--%>
					<%--onclick="cleanInfo(2)">删除</a>--%>
					<%--</div>--%>
					<input id="recommenderIds" name="recommenderIds" type="hidden"/>
					<input id="recommenderPhones" name="recommenderPhones" type="hidden"/>
					<table class="grid1"  id="recommender_grid" >
						<thead>
						<tr>
							<th>办事处</th>
							<th>推荐人姓名</th>
							<th>推荐人电话</th>
							<th>推荐人类型</th>
							<th>设备型号</th>
							<th>设备标识</th>
							<th>验证步骤</th>
							<th>账户状态</th>
							<th>增加时间</th>
							<th>解绑次数</th>
							<th>门店数量</th>
						</tr>
						</thead>
						<tbody id="recommenderItems">
						</tbody>
					</table>
				</div>
				<div title="外勤人员" style="padding:5px;">
					<%--<div style="background-color: #e9f1ff;padding: 5px;font-weight: bold;">--%>
					<%--<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconcls="icon-add"--%>
					<%--onclick="addInfo(3)">添加</a>--%>
					<%--<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconcls="icon-delete"--%>
					<%--onclick="cleanInfo(3)">删除</a>--%>
					<%--</div>--%>
					<input id="staffIds" name="staffIds" type="hidden"/>
					<input id="staffPhones" name="staffPhones" type="hidden"/>
					<table class="grid1" id="staff_grid" >
						<thead>
						<tr>
							<th>员工号</th>
							<th>员工帐号</th>
							<th>员工姓名</th>
							<th>员工类型</th>
							<th>性别</th>
							<th>部门名称</th>
							<th>部门职务</th>
							<th>汇报对象</th>
							<th>账户状态</th>
							<th>手机号</th>
							<th>设备型号</th>
							<th>设备标识</th>
							<th>验证步骤</th>
						</tr>
						</thead>
						<tbody id="staffItems">
						</tbody>
					</table>
				</div>
			</div>
		</div>

		<!--  调查问题 -->
		<p style=" font-weight: bold;  padding: 2px; ">调查问题</p>
		<div style="padding:5px; height:340px;" >
			<table class="grid1" id="question_grid" >
				<thead>
				<tr>
					<th>问题类型</th>
					<th>题目</th>
					<th>操作</th>
				</tr>
				</thead>
				<tbody id="questionItems">
				</tbody>
			</table>
		</div>

		<!--  备注 -->
		<p style=" font-weight: bold;  padding: 2px; ">备注</p>
		<div class="col" style="width:98%">
			<div class="td" style="width:98%">
				<textarea name="remark" cols="50" rows="4" maxlength="1000" style="width: 659px;margin-left: 50px;"></textarea>
			</div>
		</div>

		<!--页面grid json 存储 隐藏-->
		<!-- 会员 -->
		<div class="col" style="width:98%; display: none;" >
			<label class="th ">会员：</label>
			<div class="td">
				<textarea id="member_grid_rows" name="member_grid_rows" cols="50" rows="4" maxlength="1000" style="width: 659px;margin-left: 50px;"></textarea>
			</div>
		</div>
		<!-- 推荐人 -->
		<div class="col" style="width:98%; display: none;" >
			<label class="th ">推荐人：</label>
			<div class="td">
				<textarea id="recommender_grid_rows" name="recommender_grid_rows" cols="50" rows="4" maxlength="1000" style="width: 659px;margin-left: 50px;"></textarea>
			</div>
		</div>
		<!-- 外勤人员 -->
		<div class="col" style="width:98%; display: none;" >
			<label class="th ">外勤人员：</label>
			<div class="td">
				<textarea id="staff_grid_rows" name="staff_grid_rows" cols="50" rows="4" maxlength="1000" style="width: 659px;margin-left: 50px;"></textarea>
			</div>
		</div>
		<!-- 问题 -->
		<div class="col" style="width:98%; display: none;" >
			<label class="th ">问题：</label>
			<div class="td">
				<textarea id="question_grid_rows" name="question_grid_rows" cols="50" rows="4" maxlength="1000" style="width: 659px;margin-left: 50px;"></textarea>
			</div>
		</div>

	</div>
</script>
<script type="text/javascript">
    $(function () {
        /*表单数据加载成功的事件处理函数*/
        function onFormLoadSuccess(data) {
            $.extend($.fn.validatebox.defaults.rules, {
                number: {
                    validator: function (value, param) {
                        return /^\d+$/.test(value);
                    },
                    message: '请输入数字'
                }
            });

        }

        var formData = {};
        //构造pageform（主数据）
        var easyUIFormParams = {onLoadSuccess: onFormLoadSuccess};
        var url = '${pageContext.request.contextPath}/api/${modulePath}?id=${id}';
        var pageForm = new PageForm('formMain', url, easyUIFormParams, null, function (data) {

            // 会员表格
            $('#member_grid').datagrid({
                idField: 'ID',
                fit:true,
                fitColumns:true,
                rownumbers:true,
                queryParams: {

                },
                toolbar: [{
                    iconCls: 'icon-add',
                    text:'添加',
                    handler: function(){
                        addInfo(1);
                    }
                },{
                    iconCls: 'icon-delete',
                    text:'删除',
                    handler: function(){
                        //alert('删除');
                        var rows =$('#member_grid').datagrid('getSelections');
                        if (!rows || rows.length === 0) {
                            $.messager.alert('警告', "请选择数据！", "warning");
                            return;
                        }
                        // 从后向前删除 （删除的时候行号会动态变化，导致删除出错，此时解决方法为将遍历删除从后往前删，这样就不会有错）
                        for (var i = rows.length - 1; i >= 0; i--) {
                            var index = $('#member_grid').datagrid('getRowIndex',rows[i]);
                            $('#member_grid').datagrid('deleteRow', index);
                        }
                        //==========提交使用 非常重要=========START
                        var _rows = $('#member_grid').datagrid('getRows');
                        cleanInfoNew(1,_rows);
                        //==========提交使用 非常重要=========START

                    }

                }],
                onLoadSuccess:function(data){

                },
                columns:[[
                    {field:'ck',checkbox:true,hidden:false},
                    {field:'ID',title:'id',width:100,hidden:true},
                    {field:'CHECKCITYNAME',title:'办事处',width:100},
                    {field:'REALNAME',title:'会员姓名',width:100},
                    {field:'MOBILEPHONE',title:'会员电话',width:100},
                    {field:'REGISTERCHANNELNAME',title:'注册渠道',width:100},
                    {field:'REGISTERTYPENAME',title:'注册方式',width:100},
                    {field:'ORDERQTY',title:'购买次数',width:100},
                    {field:'BABYQTY',title:'宝宝数量',width:100},
                    {field:'TOTALSCORE',title:'总积分',width:100},
                    {field:'USEDSCORE',title:'已用积分',width:100},
                    {field:'CURRSCORE',title:'未用积分',width:100},
                    {field:'USERTYPENAME',title:'推荐人类型',width:100},
                    {field:'ADDBYREALNAME',title:'推荐人姓名',width:100},
                    {field:'CELLPHONE',title:'推荐人电话',width:100},
                    {field:'ADDTIME',title:'注册时间',width:100}
                ]]
            });


            // 推荐人表格
            $('#recommender_grid').datagrid({
                idField: 'ID',
                fit:true,
                fitColumns:true,
                rownumbers:true,
                queryParams: {

                },
                toolbar: [{
                    iconCls: 'icon-add',
                    text:'添加',
                    handler: function(){
                        addInfo(2);
                    }
                },{
                    iconCls: 'icon-delete',
                    text:'删除',
                    handler: function(){
                        //alert('删除');
                        var rows =$('#recommender_grid').datagrid('getSelections');
                        if (!rows || rows.length === 0) {
                            $.messager.alert('警告', "请选择数据！", "warning");
                            return;
                        }
                        // 从后向前删除 （删除的时候行号会动态变化，导致删除出错，此时解决方法为将遍历删除从后往前删，这样就不会有错）
                        for (var i = rows.length - 1; i >= 0; i--) {
                            var index = $('#recommender_grid').datagrid('getRowIndex',rows[i]);
                            $('#recommender_grid').datagrid('deleteRow', index);
                        }
                        //==========提交使用 非常重要=========START
                        var _rows = $('#recommender_grid').datagrid('getRows');
                        cleanInfoNew(2,_rows);
                        //==========提交使用 非常重要=========START

                    }

                }],
                onLoadSuccess:function(data){

                },
                columns:[[
                    {field:'ck',checkbox:true,hidden:false},
                    {field:'ID',title:'id',width:100,hidden:true},
                    {field:'REGIONNAME',title:'办事处',width:100},
                    {field:'REALNAME',title:'推荐人姓名',width:100},
                    {field:'CELLPHONE',title:'推荐人电话',width:100},
                    {field:'USERTYPENAME',title:'推荐人类型',width:100},
                    {field:'EQUIPMENTMODEL',title:'设备型号',width:100},
                    {field:'EQUIPMENTID',title:'设备标识',width:100},
                    {field:'OPERATIONSTEPSNAME',title:'验证步骤',width:100},
                    {field:'USERSTATUSNAME',title:'账户状态',width:100},
                    {field:'ADDTIME',title:'增加时间',width:100},
                    {field:'UNBUNDLINGQTY',title:'解绑次数',width:100},
                    {field:'STORENUM',title:'门店数量',width:100}
                ]]
            });

            // 外勤表格
            $('#staff_grid').datagrid({
                idField: 'ID',
                fit:true,
                fitColumns:true,
                rownumbers:true,
                queryParams: {

                },
                toolbar: [{
                    iconCls: 'icon-add',
                    text:'添加',
                    handler: function(){
                        addInfo(3);
                    }
                },{
                    iconCls: 'icon-delete',
                    text:'删除',
                    handler: function(){
                        //alert('删除');
                        var rows =$('#staff_grid').datagrid('getSelections');
                        if (!rows || rows.length === 0) {
                            $.messager.alert('警告', "请选择数据！", "warning");
                            return;
                        }
                        // 从后向前删除 （删除的时候行号会动态变化，导致删除出错，此时解决方法为将遍历删除从后往前删，这样就不会有错）
                        for (var i = rows.length - 1; i >= 0; i--) {
                            var index = $('#staff_grid').datagrid('getRowIndex',rows[i]);
                            $('#staff_grid').datagrid('deleteRow', index);
                        }
                        //==========提交使用 非常重要=========START
                        var _rows = $('#staff_grid').datagrid('getRows');
                        cleanInfoNew(3,_rows);
                        //==========提交使用 非常重要=========START

                    }

                }],
                onLoadSuccess:function(data){

                },
                columns:[[
                    {field:'ck',checkbox:true,hidden:false},
                    {field:'ID',title:'id',width:100,hidden:true},
                    {field:'EMPNO',title:'员工号',width:100},
                    {field:'USERNAME',title:'员工帐号',width:100},
                    {field:'REALNAME',title:'员工姓名',width:100},
                    {field:'USERTYPENAME',title:'员工类型',width:100},
                    {field:'SEXNAME',title:'性别',width:100},
                    {field:'DEPTNAME',title:'部门名称',width:100},
                    {field:'POSTNAME',title:'部门职务',width:100},
                    {field:'PARENTUSERNAME',title:'汇报对象',width:100},
                    {field:'USERSTATUSNAME',title:'账户状态',width:100},
                    {field:'CELLPHONE',title:'手机号',width:100},
                    {field:'EQUIPMENTMODEL',title:'设备型号',width:100},
                    {field:'EQUIPMENTID',title:'设备标识',width:100},
                    {field:'OPERATIONSTEPSNAME',title:'验证步骤',width:100}

                ]]
            });


            // 问题表格
            $('#question_grid').datagrid({
                idField: 'ID',
                fit:true,
                fitColumns:false,
                rownumbers:false,
                // singleSelect:true,
                queryParams: {

                },
                toolbar: [{
                    iconCls: 'icon-add',
                    text:'添加',
                    handler: function(){
                        add_question();
                    }
                },{
                    iconCls: 'icon-edit',
                    text:'修改',
                    handler: function(){
                        var rows =$('#question_grid').datagrid('getSelections');
                        if (!rows || rows.length === 0) {
                            $.messager.alert('警告', "请选择数据！", "warning");
                            return;
                        }
                        if (rows.length > 1) {
                            $.messager.alert('警告', "每次只能修改一条！", "warning");
                            return;
                        }

                        mod_question(rows[0]);


                    }
                },{
                    iconCls: 'icon-delete',
                    text:'删除',
                    handler: function(){
                        //alert('删除');
                        var rows =$('#question_grid').datagrid('getSelections');
                        if (!rows || rows.length === 0) {
                            $.messager.alert('警告', "请选择数据！", "warning");
                            return;
                        }
                        $.messager.confirm('确认操作', '确认要删除吗？', function (r) {
                            if (r) {
                                // 从后向前删除 （删除的时候行号会动态变化，导致删除出错，此时解决方法为将遍历删除从后往前删，这样就不会有错）
                                for (var i = rows.length - 1; i >= 0; i--) {
                                    var index = $('#question_grid').datagrid('getRowIndex',rows[i]);
                                    $('#question_grid').datagrid('deleteRow', index);
                                }
                                // 删除后重新对问题排序
                                var qRows = $('#question_grid').datagrid('getRows');
                                $.each(qRows,function(i,o){
                                    // 待修改行index
                                    var _index =  $('#question_grid').datagrid('getRowIndex',o);
                                    o["SORTNUM"] = _index + 1;
                                    // exec 修改行
                                    $('#question_grid').datagrid('updateRow',{
                                        index: _index,
                                        row: o
                                    });
                                    // exec 刷新行
                                    $('#question_grid').datagrid('refreshRow', _index);
                                });

                            }
                        });

                    }

                },{
                    iconCls: 'icon-arrow_up',
                    text:'向上移动',
                    handler: function(){
                        //alert('删除');
                        var rows =$('#question_grid').datagrid('getSelections');

                        if (!rows || rows.length === 0) {
                            $.messager.alert('警告', "请选择数据！", "warning");
                            return;
                        }

                        if (rows.length > 1) {
                            $.messager.alert('警告', "请选择1条数据！", "warning");
                            return;
                        }

                        var row = $("#question_grid").datagrid('getSelected');
                        var index = $("#question_grid").datagrid('getRowIndex', row);
                        mysort(index, 'up', 'question_grid');


                    }
                },{
                    iconCls: 'icon-arrow_down',
                    text:'向下移动',
                    handler: function(){
                        //alert('删除');
                        var rows =$('#question_grid').datagrid('getSelections');

                        if (!rows || rows.length === 0) {
                            $.messager.alert('警告', "请选择数据！", "warning");
                            return;
                        }

                        if (rows.length > 1) {
                            $.messager.alert('警告', "请选择1条数据！", "warning");
                            return;
                        }

                        var row = $("#question_grid").datagrid('getSelected');
                        var index = $("#question_grid").datagrid('getRowIndex', row);
                        mysort(index, 'down', 'question_grid');

                    }
                }


                ],
                onLoadSuccess:function(data){

                },
                columns:[[
                    {field:'ck',checkbox:true,hidden:false},
                    {field:'ID',title:'id',width:100,hidden:true},
                    {field:'SORTNUM',title:'排序号',width:50,hidden:false},
                    {field:'QUESTIONTYPENAME',title:'问题类型',width:100},
                    {field:'QUESTIONTITLE',title:'题目',width:1400},
                    {field:'operation',title:'操作',width:50,
                        formatter: function(value,row,index){
                            var cell_url = '<a href="javascript:void(0);" onclick="operation('+index+')">查看</a>';
                            return cell_url;
                        }
                    },
                    //-----------以下是隐藏表单 提交使用---------------------------
                    {field:'SURVEYINFOID',title:'问卷调查信息表ID',width:100,hidden:true},
                    {field:'QUESTIONCONTENT',title:'题干',width:100,hidden:true},
                    {field:'REQUIREDSTATUS',title:'是否必答',width:100,hidden:true},
                    {field:'QUESTIONTYPE',title:'问题类型',width:100,hidden:true},
                    {field:'OPTIONSA',title:'题目选项A',width:100,hidden:true},
                    {field:'OPTIONSB',title:'题目选项B',width:100,hidden:true},
                    {field:'OPTIONSC',title:'题目选项C',width:100,hidden:true},
                    {field:'OPTIONSD',title:'题目选项D',width:100,hidden:true},
                    {field:'OPTIONSE',title:'题目选项E',width:100,hidden:true},
                    {field:'OPTIONSF',title:'题目选项F',width:100,hidden:true},
                    {field:'OPTIONSG',title:'题目选项G',width:100,hidden:true}
                ]]
            });


            // 根据json 装配表格
            // 会员
            var mRows = JSON.parse($('#member_grid_rows').val());
            $('#member_grid').datagrid('loadData',mRows);
            cleanInfoNew(1,mRows);
            // 推荐人
            var rRows = JSON.parse($('#recommender_grid_rows').val());
            $('#recommender_grid').datagrid('loadData',rRows);
            cleanInfoNew(2,rRows);
            // 外勤
            var sRows = JSON.parse($('#staff_grid_rows').val());
            $('#staff_grid').datagrid('loadData',sRows);
            cleanInfoNew(3,sRows);
            // 问题
            $('#question_grid').datagrid('loadData',JSON.parse($('#question_grid_rows').val()));


        }, null, 'edit');
        //初始化表单
        function initForm(){

            pageForm.init().loadForm(formData);

            // 提交表单
            $('#btnSave').on('click', function () {

                // 进行框架验证
                var $form = $('#formMain');
                if (!$form.form('validate')) {
                    return false;
                }

                // 会员
                var member_grid_rows = $('#member_grid').datagrid('getRows');
                var member_grid_len = member_grid_rows.length;
                // 推荐人
                var recommender_grid_rows = $('#recommender_grid').datagrid('getRows');
                var recommender_grid_len = recommender_grid_rows.length;
                // 外勤
                var staff_grid_rows = $('#staff_grid').datagrid('getRows');
                var staff_grid_len = staff_grid_rows.length;
                // 校验 调查范围
                if(0 == member_grid_len && 0 == recommender_grid_len && 0 == staff_grid_len){
                    $.messager.alert('警告', "会员、推荐人、外勤人员，请至少选择一种调查范围", "warning");
                    return false;
                }

                // 问题
                var question_grid_rows = $('#question_grid').datagrid('getRows');
                var question_grid_len = question_grid_rows.length;
                if(0 == question_grid_len){
                    $.messager.alert('警告', "请添加调查问题", "warning");
                    return false;
                }

                //========================赋值表单提交===========================START
                // 会员
                $('#member_grid_rows').val(JSON.stringify(member_grid_rows));
                // 推荐人
                $('#recommender_grid_rows').val(JSON.stringify(recommender_grid_rows));
                // 外勤
                $('#staff_grid_rows').val(JSON.stringify(staff_grid_rows));
                // 问题
                $('#question_grid_rows').val(JSON.stringify(question_grid_rows));
                //========================赋值表单提交===========================END



                pageForm.submitForm();
            });



        }

        PageForm.prepareFormWidget($('.headerTable'), $($('#headerTmpl').html()), '${pageContext.request.contextPath}','${modulePath}', 'edit',initForm);

    });

    // 添加 调查范围：1 会员2 推荐人3 外勤人员
    function addInfo(index) {

        var url = "";
        var title = "";
        var IDS = "";

        if (index == 1) {
            url = "${pageContext.request.contextPath}/view/ebms/surveyInfo/selectMembers";
            title = "添加会员";
            IDS = "#memberIds";
        } else if (index == 2) {
            url = "${pageContext.request.contextPath}/view/ebms/surveyInfo/selectRecommenders";
            title = "添加推荐人";
            IDS = "#recommenderIds";
        } else {
            url = "${pageContext.request.contextPath}/view/ebms/surveyInfo/selectStaffs";
            title = "添加外勤人员";
            IDS = "#staffIds";
        }

        // 开启对应的编辑页
        var content = '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';
        var boarddiv = '<div id="msgwindow" title="' + title + '"></div>'//style="overflow:hidden;"可以去掉滚动条
        $(document.body).append(boarddiv);
        var win = $('#msgwindow').window({
            top: 100,
            content: content,
            width: 1000,
            height: 600,
            modal: true,
            title: title,
            onClose: function () {
                // 局部刷新页面表格
                var buildDetailIds = $(IDS).val();

                if (index == 1) {
                    buildMemberDetails(buildDetailIds);
                } else if (index == 2) {
                    buildRecommenderDetails(buildDetailIds);
                } else {
                    buildStaffDetails(buildDetailIds);
                }
            }
        });
        win.dialog('open');
    }

    // 删除 调查范围表格，此处是全部删除，弃用（弃用）
    function cleanInfo(index) {
        var IDS = "";
        var PHONES = "";
        var TOBDYIDS = "";

        if (index == 1) {
            IDS = "#memberIds";
            PHONES = "#memberPhones";
            TOBDYIDS = "#memberItems";
        } else if (index == 2) {
            IDS = "#recommenderIds";
            PHONES = "#recommenderPhones";
            TOBDYIDS = "#recommenderItems";
        } else {
            IDS = "#staffIds";
            PHONES = "#staffPhones";
            TOBDYIDS = "#staffItems";
        }

        $(IDS).val("");
        $(PHONES).val("");
        $(TOBDYIDS).empty();
    }

    // 删除调查范围 删除勾选的表格 启用
    function cleanInfoNew(index,_rows) {
        var IDS = "";
        var PHONES = "";
        var TOBDYIDS = "";

        if (index == 1) {
            IDS = "#memberIds";
            PHONES = "#memberPhones";
            TOBDYIDS = "#memberItems";

            // 清空老数据
            $(IDS).val("");
            $(PHONES).val("");
            $(TOBDYIDS).empty();

            // 添加新数据
            var _id_arr = new Array();
            var _phone_arr = new Array();
            $.each(_rows,function(i,o){
                _id_arr.push(o.ID);
                _phone_arr.push(o.MOBILEPHONE);
            });
            $(IDS).val(_id_arr.join());
            $(PHONES).val(_phone_arr.join());

        } else if (index == 2) {
            IDS = "#recommenderIds";
            PHONES = "#recommenderPhones";
            TOBDYIDS = "#recommenderItems";

            // 清空老数据
            $(IDS).val("");
            $(PHONES).val("");
            $(TOBDYIDS).empty();

            // 添加新数据
            var _id_arr = new Array();
            var _phone_arr = new Array();
            $.each(_rows,function(i,o){
                _id_arr.push(o.ID);
                _phone_arr.push(o.CELLPHONE);
            });
            $(IDS).val(_id_arr.join());
            $(PHONES).val(_phone_arr.join());

        } else {
            IDS = "#staffIds";
            PHONES = "#staffPhones";
            TOBDYIDS = "#staffItems";

            // 清空老数据
            $(IDS).val("");
            $(PHONES).val("");
            $(TOBDYIDS).empty();

            // 添加新数据
            var _id_arr = new Array();
            var _phone_arr = new Array();
            $.each(_rows,function(i,o){
                _id_arr.push(o.ID);
                _phone_arr.push(o.CELLPHONE);
            });
            $(IDS).val(_id_arr.join());
            $(PHONES).val(_phone_arr.join());

        }





    }

    // 调查范围，会员
    function buildMemberDetails(ids) {
        $.ajax({
            url: '${pageContext.request.contextPath}/api/ebms/surveyInfo/getMemberDetailsByIds?ids=' + ids,
        }).done(function (res) {
            $('#member_grid').datagrid('loadData',res.data);
        });
    }

    // 调查范围，推荐人
    function buildRecommenderDetails(ids) {

        $.ajax({
            url: '${pageContext.request.contextPath}/api/ebms/surveyInfo/getRecommenderDetailsByIds?ids=' + ids,
        }).done(function (res) {
            $('#recommender_grid').datagrid('loadData',res.data);
        });
    }

    // 调查范围，外勤人员
    function buildStaffDetails(ids) {
        $.ajax({
            url: '${pageContext.request.contextPath}/api/ebms/surveyInfo/getStaffDetailsByIds?ids=' + ids,
        }).done(function (res) {
            $('#staff_grid').datagrid('loadData',res.data);
        });
    }


    // 上移 下移
    function mysort(index, type, gridname) {
        if ("up" == type) {
            if (index != 0) {
                var toup = $('#' + gridname).datagrid('getData').rows[index];
                var todown = $('#' + gridname).datagrid('getData').rows[index - 1];


                var _sortNum = index + 1;
                toup['SORTNUM'] = index;
                todown['SORTNUM'] = index + 1;

                $('#' + gridname).datagrid('getData').rows[index] = todown;
                $('#' + gridname).datagrid('getData').rows[index - 1] = toup;
                $('#' + gridname).datagrid('refreshRow', index);
                $('#' + gridname).datagrid('refreshRow', index - 1);
                $('#' + gridname).datagrid('unselectAll');
                $('#' + gridname).datagrid('selectRow', index - 1);


            }
        } else if ("down" == type) {
            var rows = $('#' + gridname).datagrid('getRows').length;
            if (index != rows - 1) {
                var todown = $('#' + gridname).datagrid('getData').rows[index];
                var toup = $('#' + gridname).datagrid('getData').rows[index + 1];


                var _sortNum = index + 1;
                toup['SORTNUM'] = _sortNum;
                todown['SORTNUM'] = _sortNum + 1;


                $('#' + gridname).datagrid('getData').rows[index + 1] = todown;
                $('#' + gridname).datagrid('getData').rows[index] = toup;
                $('#' + gridname).datagrid('refreshRow', index);
                $('#' + gridname).datagrid('refreshRow', index + 1);
                $('#' + gridname).datagrid('unselectAll');
                $('#' + gridname).datagrid('selectRow', index + 1);


            }
        }
    }


    // 添加问题 页面级别保存
    function add_question() {

        var url = "${pageContext.request.contextPath}/view/ebms/surveyInfo/addQuestion";
        var title = "添加问题";


        // 开启对应的编辑页
        var content = '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="yes"></iframe>';
        var boarddiv = '<div id="msgwindow" title="' + title + '"></div>'//style="overflow:hidden;"可以去掉滚动条
        $(document.body).append(boarddiv);
        var win = $('#msgwindow').window({
            top: 100,
            content: content,
            width: 1000,
            height: 750,
            modal: true,
            title: title,
            onClose: function () {
                // $('#msgwindow').remove();
            }
        });
        win.dialog('open');
    }

    // 修改问题 页面级别保存
    function mod_question(_row) {

        var url = "${pageContext.request.contextPath}/view/ebms/surveyInfo/editQuestion";
        var title = "修改问题";


        // 开启对应的编辑页
        var content = '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="yes"></iframe>';
        var boarddiv = '<div id="msgwindow" title="' + title + '"></div>'//style="overflow:hidden;"可以去掉滚动条
        $(document.body).append(boarddiv);
        var win = $('#msgwindow').window({
            top: 100,
            content: content,
            width: 1000,
            height: 750,
            modal: true,
            title: title,
            onClose: function () {
                // $('#msgwindow').remove();
            }
        });
        win.dialog('open');
    }


    // 查看
    function operation(_index){
        // 获取行
        var _row = $('#question_grid').datagrid('getRows')[_index];
        // 查询专用数据
        $('body').data('operation_data',_row);

        var url = "${pageContext.request.contextPath}/view/ebms/surveyInfo/detailQuestion";
        var title = "查看问题";


        // 开启对应的编辑页
        var content = '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="yes"></iframe>';
        var boarddiv = '<div id="msgwindow" title="' + title + '"></div>'//style="overflow:hidden;"可以去掉滚动条
        $(document.body).append(boarddiv);
        var win = $('#msgwindow').window({
            top: 100,
            content: content,
            width: 1000,
            height: 750,
            modal: true,
            title: title,
            onClose: function () {
                // $('#msgwindow').remove();
            }
        });
        win.dialog('open');
    }



</script>
